<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'detail';
model('jy_weishop/member')->checklogin();
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	if(!$id){
		$all=pdo_getall('jy_weishop_queue_member',array('uniacid'=>$_SESSION['uniacid'],'status'=>0,'mid'=>$_SESSION['uid']),'','','id desc');
		$return['item']=$all[0];
	}else{
		$return['item']=pdo_get('jy_weishop_queue_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}
	if(!$return['item']['id']){
		$ispass=pdo_get('jy_weishop_queue_member',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'mid'=>$_SESSION['uid'],'createtime >'=>TIMESTAMP-7200));
		if($ispass['number']){
			exi('您的当前排号'.$ispass['number'].'已过，重新取号！','error','jy_weidish_xibei/getqueue//from=queue');
		}else{
			exi('您还未取号！','error','jy_weidish_xibei/getqueue//from=queue');
		}
	}
	$return['item']['usernum']=$return['item']['num']+$return['item']['childnum'];
	$return['queue']=pdo_get('jy_weishop_queue',array('uniacid'=>$_SESSION['uniacid'],'id'=>$return['item']['queue_id']));
	$return['store']=pdo_get('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$return['item']['store_id']));
	set_html('title','排号详情');
	exi($return);
}
if($_RQ['op']=='getredlasttime'){
	$memberid=$_RQ['memberid'];
	$getredtime=pdo_getcolumn('jy_weishop_queue_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$memberid),'getredtime');
	$jiangetime=intval($return['pluginset']['red_time'])?:5;
	$jiangetime=$jiangetime*60;
	if($getredtime){
		$passtime=time()-$getredtime;
		//过期未领，自动生成领取时间
		if($passtime>$jiangetime+60){
			pdo_update('jy_weishop_queue_member',array('getredtime'=>time()),array('uniacid'=>$_SESSION['uniacid'],'id'=>$memberid));
			$redlasttime=$jiangetime;
		}elseif($passtime<$jiangetime){
			$redlasttime=time()-$getredtime;
		}else{
			$redlasttime=0;
		}
		$return['redlasttime']=model('jy_weishop/model')->date($redlasttime);
	}else{
		pdo_update('jy_weishop_queue_member',array('getredtime'=>time()),array('uniacid'=>$_SESSION['uniacid'],'id'=>$memberid));
		$return['redlasttime']=model('jy_weishop/model')->date($jiangetime);
	}
	exi($return);
}
if($_RQ['op']=='getred'){
	$return['pluginset']['red_min']=$return['pluginset']['red_min']?:1;
	$return['pluginset']['red_max']=$return['pluginset']['red_max']?:3;
	$money=rand($return['pluginset']['red_min'],$return['pluginset']['red_max']);
	$memberid=$_RQ['memberid'];
	$log_id=model('core/member')->add_credit1($_SESSION['uid'],$money,$remark='排号红包雨',$from_plugin='jy_weidish_xibei',$tag='queue');
	pdo_update('jy_weishop_queue_member',array('getredtime'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'id'=>$memberid));
	$redlasttime=intval($return['pluginset']['red_time'])?:5;
	$redlasttime=$redlasttime*60;
	$return['money']=$money;
	$return['redlasttime']=model('jy_weishop/model')->date($redlasttime);
	exi($return);
}
?>